/*评论表单验证*/
$(function () {
    $('.ui.form').form({
        fields: {
            content: 'empty',
            nickName: 'empty',
            email: ['empty', 'email']
        }
    })

    $('#push-comment-btn').click(function () {
        const success = $('.ui.form').form('validate form');
        if (success) {
            postComment()
        }
    })


    /**
     * 提交评论信息
     */
    function postComment() {
        $("#comment-container").load('/comment', {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickName": $("[name='nickName']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val()
        }, function () {
            clearContent();
        });
    }


})


function clearContent() {
    $("[name='content']").val('');
    $("[name='parentComment.id']").val(-1);
    $("[name='content']").attr("placeholder", "请输入评论信息...");
}

function reply(obj) {
    const commentId = $(obj).data('commentid');
    const commentNickname = $(obj).data('commentnickname');
    $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
    $("[name='parentComment.id']").val(commentId);
}